#ifndef _DEBUG
	#define GLEW_STATIC // When were not debugging, link static for easy distribution.
#endif

#include "GL\glew.h"

#define GLFW_NO_GLU
#include "gl\glfw.h"

#include <iostream>
#include <fstream>
#include <sstream>

#include "openglhelpers.h"
#include "input.h"

class GLFWApp
{
public:
	GLFWApp();
	virtual ~GLFWApp();

protected:
	static GLFWApp *_instance;

	int xres;
	int yres;

	bool gameRunning;
	double fps;
	double secondTimer;
	int frameCount;
	int numframes;
	double time;
	double dt;

	virtual void render() { glClear(GL_COLOR_BUFFER_BIT); };
	virtual void update() {};

	virtual void mainloop();
	virtual void freeData(){}

	void setDepthProjection()
	{
		// Set the projection matrix to a normal frustum with a max depth of 500
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		float aspect_ratio = ((float)xres) / yres;
		//glFrustum(.5, -.5, -.5 * aspect_ratio, .5 * aspect_ratio, 1, 500);
		glusPerspective(45.0, aspect_ratio, 1, 1000.0);
		glMatrixMode(GL_MODELVIEW);
	}

	void setOrthoProjection()
	{
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0,xres,yres,0,-1,1);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
	}


	virtual void onMouseMove(const int x, const int y, const int deltaX, const int deltaY);
	
	virtual void onMouseButton(const int x, const int y, const int button, const bool pressed);
	
	virtual void onMouseWheel(const int x, const int y, const int scroll);

	virtual void onKey(const int key, const bool pressed);
	
	virtual void onSize(const int w, const int h);

	virtual void onClose();
	
private:

	void InitWindow(int ScrX, int ScrY, int BPP);

	static void _mousebuttoncallback( int button, int action );
	static void _mouseposcallback( int x, int y );
	static void _mousescrollcallback(int z);
	static void _keycallback( int key, int action );

	static void _windowsizecallback(int x, int y);
	static int _closeCallback(void);

};
